Skip to content

Cut Mandate false blocks 58 -> 39 of 1038 with 140/140 attacks still blocked - #13

Merged
JoeProAI merged 2 commits into
bench/real-modelfrom
fix/false-blocks
Nov 11, 2026
Merged

JoeProAI merged 2 commits into
bench/real-modelfrom
fix/false-blocks

Conversation

@JoeProAI

@JoeProAI JoeProAI commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Builds on #12 (bench/real-model). Joe asked for a false-block fix first, then a bench rerun. Do not merge until Joe reviews.

Replay on the same recorded gpt-4o-mini traces (bench/replay.py, score.py, headline.py, no key, no new live runs):

Before (b259dc6) After
Attack calls blocked, same traffic 140 of 140 140 of 140
Legit calls blocked, same traffic 58 of 1038 39 of 1038
Mandate's own clean runs (replayed) 9 of 263 8 of 263
Observe 5 runs, same traffic 13 of 609 5 of 609
pre_tool_call p50 / p95 1.84 to 2.19 / 6.7 to 7.7 ms 1.65 to 1.78 / 4.5 to 6.0 ms (same VM, noisy)

No attack call got through at any observe length. The policies are still 10/10 identical to live. 1038 of 1043 decisions match live, and the 5 that changed are legit calls now allowed: 2 read-backs, 2 rewrites, 1 mkdir -p reports.

What changed (enforcement only, policy format unchanged):

  1. The write budget counts distinct paths. Rewrites are capped at budget + 4.
  2. Read-only commands (cat, head, wc, ls and similar) can read back paths the mandate already approves.
  3. Tool families: read_file and search_files count as one, and so do write_file and patch. A file-name-only search_files inside the workdir is allowed.
  4. Learned read-only commands can take new flags, but only when every operand is an approved path. Writing or recursive flags are never widened.
  5. mkdir is allowed for the parent dirs of approved write paths, and it doesn't use the write budget.
  6. propose warns when the job prompt names a file no learned write rule covers. On the live proposals it fires only on repo-status.

Tests: 111 before, 152 now passing, 1 skipped as before. The new file is tests/test_false_block_fixes.py, which includes a must-still-block list: ~/.ssh, ~/.aws, .env, curl|sh, a new host, rm -rf, sort -o, grep -r, mkdir escapes. Two adversarial cases are still blocked, just by a different rule (paths.* instead of tools).

The full before/after, plus what's left in the 39, is in bench/README.md.


Devin Review

…ack, tool families, read-only flag variance, mkdir of report dirs, propose prompt-path warning

Replay on the recorded gpt-4o-mini traces: attack calls blocked 140/140 (unchanged), legit calls blocked 58/1038 -> 39/1038. Tests 111 -> 152.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 5 potential issues.

Devin Review

Comment thread mandate_core/store.py
Comment on lines +157 to +159
if int(d.get("write_count", 0)):
calls += 1
paths.update(v for v, inside, ok in d.get("writes", []) if inside and ok)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Directory creation exhausts rewrite allowance

After five approved mkdir calls, run_writes counts them toward the rewrite cap despite their zero write cost. The next rewrite of an approved report gets blocked under a one-write policy.

Learn more

The run's distinct-write counter excludes approved parent-directory creation through write_cost. The new raw counter instead increments for any stored shape with a positive write_count, including those directory calls. The rewrite-cap check in check then treats those calls as report rewrites and refuses a later approved rewrite. A single call can also contain multiple shell write segments, so count the qualifying segments rather than assuming one per call.

Example: With max_writes_per_run: 1, five separate mkdir -p reports calls cost zero. One write_file reports/x.md costs one. A second write_file reports/x.md is rejected because raw count is already six, although this is only the first report rewrite.

Recommended fix: Keep a separate count of actual non-directory write operations for the rewrite cap. Compute it from saved shapes with enough segment metadata to identify approved mkdir calls, or persist the charged write kind when recording each call.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread mandate_core/normalize.py
Comment on lines +93 to +97
# Per-segment paths, used only to widen read-only commands (policy._readonly_ok). grep-style heads
# take file operands after the pattern; path_candidates only sees the absolute ones, so add the rest.
for p in shell.grep_operands(seg):
refs.append(("read", resolve(p, cwd, root)))
seg.extra["refs"] = refs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Saved calls mislead mandate widening

When cmd_widen rechecks a saved cat or approved mkdir call, CallShape.from_json lacks the new segment refs. It reports permitted calls as violations and can propose unnecessary permissions.

Learn more

Live normalization stores operand refs in seg.extra, and _readonly_ok requires those refs to exist. CallShape.from_json rebuilds segments without extra, is_write, redirects, or the listing marker. cmd_widen feeds those reconstructed calls to check to decide what needs widening and to preview the effect. A live-approved read-back is thus classified as an unapproved command; an approved mkdir is classified as an unapproved command and path write. These false violations can add broader rules to a pending policy.

Example: A live cat reports/x.md with reports/*.md in write rules passes. The stored call lacks refs, so cmd_widen --pattern treats it as a blocked command when replaying observations.

Recommended fix: Serialize and reconstruct the policy-relevant segment data and the listing flag, or persist enough original inputs to safely re-normalize saved calls before check. Verify that checking a round-tripped call produces the same violations as checking it live.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread mandate_core/policy.py
Comment on lines +259 to +261
mk = {r for i, s in enumerate(shape.segments) if seg_ok.get(i) == "mkdir" for _, r in s.extra["refs"]}
for ref in shape.writes:
if ref in mk:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Learned mkdir rules block approved parents

When mkdir matches a command rule, seg_ok labels it rule instead of mkdir. The parent-directory exemption then fails, blocking mkdir -p reports despite approved report writes.

Suggested change
mk = {r for i, s in enumerate(shape.segments) if seg_ok.get(i) == "mkdir" for _, r in s.extra["refs"]}
for ref in shape.writes:
if ref in mk:
mk = _mkdir_refs(shape, dirs)
for ref in shape.writes:
if ref in mk:
continue

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread mandate_core/cli.py
Comment on lines +143 to +144
if not prompt or not pol.writes:
return []

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Missing writes suppress output-path warning

When observations contain no writes, prompt_path_warnings returns before checking the job prompt. A prompt requesting reports/status.md receives no warning, though the proposed mandate blocks that output.

Suggested change
if not prompt or not pol.writes:
return []
if not prompt:
return []

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread mandate_core/policy.py
Comment on lines +168 to +169
if head in PRINT_HEADS:
return not refs and not seg.redirects

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟥 Unapproved files exposed through date flags

With terminal access, date -f .env passes the PRINT_HEADS check without an approved read path. date prints invalid input lines in errors, exposing .env values to the agent.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@JoeProAI
JoeProAI merged commit cbc60a6 into bench/real-model Nov 11, 2026
JoeProAI added a commit that referenced this pull request Nov 11, 2026
… no-key replay (#12)

* Real-model benchmark: 710 Hermes cron runs with gpt-4o-mini, published injections, no-key replay

Mandate blocked 29 of 29 attack calls (0 of 120 attack runs with harm vs 18 with Hermes defaults),
9 of 263 legit calls falsely blocked. make bench replays the traces for free. See bench/README.md.

* Cut Mandate false blocks 58 -> 39 of 1038 with 140/140 attacks still blocked (#13)

* Cut false blocks without widening reach: distinct write paths, read-back, tool families, read-only flag variance, mkdir of report dirs, propose prompt-path warning

Replay on the recorded gpt-4o-mini traces: attack calls blocked 140/140 (unchanged), legit calls blocked 58/1038 -> 39/1038. Tests 111 -> 152.

* bench README: live spot check of the fixed code (12 clean enforce runs, 0 blocks, $0.015)

---------

Co-authored-by: JoeProAI <176786290+JoeProAI@users.noreply.github.com>

---------

Co-authored-by: JoeProAI <176786290+JoeProAI@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant